<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <title>Page Title</title>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <link rel='stylesheet' type='text/css' media='screen' href='main.css'>
    <script src='main.js'></script>
</head>
<body>
    
</body>
<script>
    // 1. 斐波那契数列
function fibonacci(n) {
    if (n <= 2) return 1;
    let a = 1, b = 1;
    for (let i = 3; i <= n; i++) {
        let temp = a + b;
        a = b;
        b = temp;
    }
    return b;
}

console.log("斐波那契数列第10项：", fibonacci(10));  
</script>
<script>
    // 2. 判断闰年
function isLeapYear(year) {
    return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0);
}

console.log("2024年是否为闰年：", isLeapYear(2024)); 
console.log("2100年是否为闰年：", isLeapYear(2100));    
</script>
<script>
    // 3. 猜拳游戏
function playGame() {
    const choices = ['石头', '剪刀', '布'];
    let wins = 0, losses = 0, draws = 0;

    for (let i = 1; i <= 10; i++) {
        // 获取用户输入
        let userChoice;
        do {
            userChoice = prompt(`第 ${i} 轮：请输入 1(石头)、2(剪刀)、3(布)`);
        } while (!['1', '2', '3'].includes(userChoice));
        userChoice = parseInt(userChoice) - 1;

        // 电脑随机选择
        const computerChoice = Math.floor(Math.random() * 3);

        // 判断结果
        let result;
        if (userChoice === computerChoice) {
            draws++;
            result = '平局';
        } else if (
            (userChoice === 0 && computerChoice === 1) ||
            (userChoice === 1 && computerChoice === 2) ||
            (userChoice === 2 && computerChoice === 0)
        ) {
            wins++;
            result = '你赢了';
        } else {
            losses++;
            result = '你输了';
        }

        console.log(`第 ${i} 轮：你出了 ${choices[userChoice]}，电脑出了 ${choices[computerChoice]}，结果：${result}`);
    }

    // 输出统计结果
    console.log(`游戏结束！胜：${wins}，负：${losses}，平：${draws}`);
}

// 开始游戏
playGame();    
</script>
</html>